<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">
<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery-3.1.1.js"/>"></script>

<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>病房管理</title>
<style type="text/css">
.cc_item {
	padding: 10px;
}
</style>
</head>
<body>
	<script type="text/javascript">
		$(function() {
			var  shenpi_staffId = $("#tontyiStaffId").html();
			$("#cc_hpdoctorid").val(shenpi_staffId);
			$('#cc_wardsearch').searchbox({
				searcher : function(value, name) {
					if (name == "病房名称") {
						$("#cc_AllWardtab").datagrid({
							url : 'tocc_findBywname',
							queryParams : {
								wname : value
							}
						});
					}else if (name == "病房科室") {
						$("#cc_AllWardtab").datagrid({
							url : 'tocc_findBydepartmentName',
							queryParams : {
								departmentName : value
							}
						});
					} else {
						$("#cc_AllWardtab").datagrid({
							url : 'tocc_findBywardGename',
							queryParams : {
								gename : value
							}
						});
					}

				}
			});
			var cc_wardid;
			$("#cc_showberth").linkbutton(
					{
						onClick : function(index, row) {
							var rows = $("#cc_AllWardtab")
									.datagrid("getSelections");
							if (rows.length == 1) {
								var n = rows[0].wname;
								var m = rows[0].departmentName;
								var y = rows[0].wmoney;
								
								$('#wardwin').window({
									'title' : m + n + "病房入住情况"+y+"每天"
								});
								$('#wardwin').window("open");
								//url: 'tocc_queryAllberth',
								//初始化表单
								cc_wardid = rows[0].wardid;
								$('#ccwberthtab').datagrid({
									url : 'tocc_queryAllberth',
									queryParams : {
										bwardno : cc_wardid
									}
								});
							} else {
								$.messager.alert("提示", "只能选择一条记录，您目前选择了"
										+ rows.length + "条!");
							}
					}
			});
			
			$("#cc_addWberth").linkbutton({onClick: function(){
				$.messager.confirm("提示", "确定要添加吗？", function(v){
					if(v){
						var arr = cc_wardid;
						
						//用form提交
						$('<form>').form('submit', {
						    url:'addWardBerth',
						    onSubmit: function(param){
						    	param.wid=cc_wardid;
						    },
						    success:function(data){
						    	var json = eval("(" + data + ")");
								$.messager.alert("提示", json.reason);
								$("#ccwberthtab").datagrid("reload");
								$("#cc_AllWardtab").datagrid("reload");
						    }
						});
					}
				});
			}});
			$("#cc_Wbchechu").linkbutton({onClick: function(){
				$.messager.confirm("提示", "确定要确定要撤除吗？", function(v){
					if(v){
						//获取所有选中的编号
						var ccrows = $("#ccwberthtab").datagrid("getSelections");
						
						//将编号保存到数组中
						var ccwrr = [];
						var jg=true;
						for(var i = 0; i < ccrows.length; i ++){
							if(jg){
								if(ccrows[i].berthstate=='空'){
									ccwrr.push(ccrows[i].berthno);
									alert(ccwrr);
								}else{
									jg=false;
									$.messager.alert("提示", "你选择了已有病人入住的病床！不能撤除！");
								}
							}
						}
						if(jg){
							//用form提交
							$('<form>').form('submit', {
							    url:'delWardBerth',
							    
							    onSubmit: function(param){
							    	param.bid=ccwrr;
							    },
							    success:function(data){
							    	var json = eval("(" + data + ")");
									$.messager.alert("提示", json.reason);
									$('#ccwberthtab').datagrid({
										url : 'tocc_queryAllberth',
										queryParams : {
											bwardno : cc_wardid
										}
									});
									$("#cc_AllWardtab").datagrid("reload");
							    }
							});
						}
						
					}
				});
			}});
			$("#cc_wardref").linkbutton({
				onClick : function() {
					$("#cc_AllWardtab").datagrid({
						url : 'tocc_queryAllWard'
					});
				}
			});//tocc_queryAllberth//tocc_queryWard
			$("#cc_wberth_ref").linkbutton({
				onClick : function() {
					$("#ccwberthtab").datagrid("reload");
				}
			});
		});
		$("#cc_addward").linkbutton({
			onClick : function() {
				$("#eaitwardwin").window({"title":"添加病房"});
				$("#eaitwardwin").window("open");
				$("#wberth").textbox("readonly",false);
				$('#cc_eaitwardform').form({"url":'cc_addWard'});
				
				
			}
		});
		$("#cc_wardcancel").linkbutton({
			onClick : function() {
				$("#eaitwardwin").window("close");
				$("#cc_eaitwardform").form("clear");
			}
		});
		
		$("#cc_updateward").linkbutton({
			onClick : function(index, row) {
				var rows = $("#cc_AllWardtab").datagrid("getSelections");
				if (rows.length == 1) {
					var wid= rows[0].wardid;
					$('#cc_eaitwardform').form({"url":'cc_updateWard'});
					var n = rows[0].wname;
					$("#eaitwardwin").window({"title":"修改"+n+"病房信息"});
					//$("#wmoney").textbox("setText",rows[0].wmoney);
					//$("#wname").textbox("setText",n);
					
					$('#eaitwardwin').window('open');
					 
					//初始化表单
					$.getJSON("findByccwardId", {"wid": wid}, function(data){
							$("#cc_eaitwardform").form("load", data);
							$("#wberth").textbox("readonly",true);
							$("#cc_wid").val(wid);
						});
				} else {
					$.messager.alert("提示", "只能选择一条记录，您目前选择了"
							+ rows.length + "条!");
				}
		}
		});
		
		$("#cc_wardsave").linkbutton({
			onClick : function() {
				$('#cc_eaitwardform').form('submit', {
					onSubmit : function() {
						 //返回true提交表单，返回false则阻止表单提交
			             return $(this).form('validate');
					},
					success : function(data) {
						//JSON字符串两边需要添加小括号
						var json = eval("(" + data + ")");
						$.messager.alert("提示", json.reason);
						//关闭窗口
						$('#eaitwardwin').window('close');
						//重新加载数据
						$("#cc_AllWardtab").datagrid("reload");
						$(this).form("clear");
					}
				});
			}
		});
	</script>
	<div style="display: none">
		<input id="cc_hpdoctorid" name="hpdoctorid" class="easyui-textbox"
		>
	</div>
	<table id="cc_AllWardtab" class="easyui-datagrid"
		data-options="
				fitColumns:true,
				fit:true,
				striped:true,
				rownumbers: true,
			    url: 'tocc_queryAllWard',
				border:false ,
				toolbar: '#cc_ward_btn',
				pagination:true,
				pageSize: 16,
				pageList:[16,32,64,128]
			">
		<thead>
			<tr>
				<th data-options="field:'wardid', width:'5%',checkbox:true">ID</th>
				<th data-options="field:'wname', width:'15%'">病房名称</th>
				<th data-options="field:'gename', width:'15%'">病房类别</th>
				<th data-options="field:'departmentName', width:'15%'">所属科室</th>
				<th data-options="field:'weizhurenshu', width:'10%'">剩余床位</th>
				<th data-options="field:'wmoney', width:'15%'">日消费</th>
				<th data-options="field:'address', width:'24%'">地址</th>

			</tr>
		</thead>
	</table>
	<div id="cc_ward_btn">
		<a id="cc_addward" class="easyui-linkbutton"
			data-options="iconCls:'icon-add',plain:true">新增病房</a>
		<a id="cc_updateward" class="easyui-linkbutton"
			data-options="iconCls:'icon-edit',plain:true">修改病房信息</a>
		<a id="cc_showberth" class="easyui-linkbutton"
			data-options="iconCls:'icon-help',plain:true">病房入住情况</a> <a
			id="cc_wardref" class="easyui-linkbutton"
			data-options="iconCls:'icon-reload',plain:true">刷新</a> <input
			id="cc_wardsearch" class="easyui-searchbox"
			data-options="menu:'#cc_wardee',width:220,prompt:'请输入你要查找的内容'">
	</div>
	<div id="cc_wardee" style="width: 90px">
		<div date-options="name:'name'">病房科室</div>
		<div date-options="name:'name'">病房类别</div>
		<div date-options="name:'name'">病房名称</div>
	</div>

	<div>
		<div id="wardwin" class="easyui-window"
			style="padding:0px; line-height: 150%;background: rgb(236,243,255);"
			data-options="
			iconCls:'icon-banliyewu',
		     width: 500,
		     height: 300,
		      modal:true,
		     closed: true
			">
				<table id="ccwberthtab" class="easyui-datagrid"
					data-options="
							fitColumns:true,
							fit:true,
							rownumbers: true,
							toolbar: '#cc_berthbtn',
							border:false 
						">
					<thead>
						<tr>
							<th data-options="field:'berthno',width:'6%',checkbox:true">床位编号</th>
							<th data-options="field:'bname',width:'16%'">床位号</th>
							<th data-options="field:'pname',width:'13%'">病人姓名</th>
							<th data-options="field:'icid', width:'17%'">医疗卡编号</th>
							<th data-options="field:'psex', width:'9%'">性别</th>
							<th data-options="field:'padoctorname', width:'12%'">主治医生</th>
							<th data-options="field:'pofficesname', width:'16%'">所属科室</th>
							<th data-options="field:'berthstate', width:'13%'">床位状态</th>
							
						</tr>
					</thead>
				</table>
		</div>
	</div>
	<div id="cc_berthbtn">
		 <a id="cc_addWberth" class="easyui-linkbutton"
			data-options="iconCls:'icon-add',plain:true">新置床位</a> 
			<a id="cc_Wbchechu" class="easyui-linkbutton"
			data-options="iconCls:'icon-remove',plain:true">撤除床位</a> <a
			id="cc_wberth_ref" class="easyui-linkbutton"
			data-options="iconCls:'icon-reload',plain:true">刷新</a>
	</div>
	<div style="display: none;">
		<form id="cc_berthp" action="addberthp" method="post">
			<input id="b_id" name="bertnid">
			<input id="p_id" name="patientid">
		</form>
	</div>
	<div id="eaitwardwin" class="easyui-window"
			style="padding:10px;line-height: 150%;background: rgb(236,243,255);"
			data-options="
			iconCls:'icon-banliyewu',
		     width: 370,
		     height: 270,
		      modal:true,
		     closed: true,
		     title:'病房信息操作'
			">
			
				<form id="cc_eaitwardform" action="" method="post">
					<div style="display: none">
						<input id="cc_wid" name="wid">
					</div>
					<div class="cc_item">
						<input id="wname" name="wname" class="easyui-textbox"
							data-options="label: '病房名称:',labelAlign:'right', width: 260">
					</div>
					<div class="cc_item">
						<input id="wberth" name="wberth" class="easyui-numberbox"
							data-options="label: '床位数:', labelAlign:'right',precision:0, width: 260">
					</div>
					<div class="cc_item">
					     <input id="wmoney" name="wmoney" class="easyui-numberbox" data-options="
					          labelAlign:'right', width: 260,precision:2,
					          label:'日消费:'
					     ">
					</div>
					<div class="cc_item">
						<select id="wofficesId" name="wofficesId" class="easyui-combogrid" data-options="
							labelAlign:'right', width: 260,
							label:'科室:',
							panelHeight: 'auto',
							required: true,
     						missingMessage: '科室不能为空',
							panelWidth: '303',
							pagination:true,
							pageSize: 6,
							pageList:[6,12,24,48],
							url: 'queryTbdepartment',
							idField: 'departmentNo',
							textField: 'departmentName',
							columns: [[
								{field: 'departmentNo', title: '科室编号', width: 120},
								{field: 'departmentName', title: '科室名称', width: 180},
							]]
						"></select>
					</div>
					<div class="cc_item">
						<select id="wstoId" name="wstoId" class="easyui-combogrid" data-options="
							labelAlign:'right', width: 260,
							label:'病房地址:',
							panelHeight: 'auto',
							required: true,
     						missingMessage: '病房地址不能为空',
							panelWidth: '163',
							url: 'tocc_findByStorey',
							idField: 'storeyId',
							textField: 'address',
							columns: [[
								{field: 'storeyId', title: '楼层号', width: 80},
								{field: 'address', title: '楼层和楼名', width: 80},
							]]
						"></select>
					</div>
					<div class="cc_item">
						
						<select id="wgenreid" name="wgenreid" class="easyui-combogrid" data-options="
							labelAlign:'right', width: 260,
							label:'病房类别:',
							panelHeight: 'auto',
							required: true,
     						missingMessage: '病房类别不能为空',
							panelWidth: '163',
							url: 'tocc_findByAllCcGenre',
							idField: 'genreid',
							textField: 'gename',
							columns: [[
								{field: 'genreid', title: '类别编号', width: 80},
								{field: 'gename', title: '类别名称', width: 80},
							]]
						"></select>
					</div>
					
					
					<div style="margin-left:20%;padding-top:5px">
						<a id="cc_wardsave"  class="easyui-linkbutton" data-options="iconCls:'icon-baocun'">确定</a>
						 <a id="cc_wardcancel" style="margin-left:40px" class="easyui-linkbutton" data-options="iconCls:'icon-chexiao'">取消</a>
					</div>
	
				</form>
		
	</div>
</body>
</html>